home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / snip0493.zip / KBFLIP.C < prev    next >
C/C++ Source or Header  |  1993-04-05  |  2KB  |  87 lines

  1. /*
  2. **  KBFLIP.C
  3. **
  4. **  a public domain demo by: Bob Stout
  5. */
  6.  
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <ctype.h>
  10. #include <process.h>
  11.  
  12. #ifdef __TURBOC__
  13.  #define FAR far
  14. #else
  15.  #define FAR _far
  16. #endif
  17.  
  18. #define SHOW(str) fputs(str"\n", stderr)
  19.  
  20. #define BitSet(arg,posn) ((arg) | (1L << (posn)))
  21. #define BitClr(arg,posn) ((arg) & ~(1L << (posn)))
  22.  
  23. #define LOCKS_POSN 4
  24. #define BYTE unsigned char
  25.  
  26. BYTE FAR *kb_status = (BYTE FAR *) 0x00400017;
  27.  
  28. /*
  29. **  Tell the folks how this works
  30. */
  31.  
  32. void usage(void)
  33. {
  34.       SHOW("Usage: KBFLIP {+|-}[switches] [...{+|-}[switches]]");
  35.       SHOW("Where \"switches\" are one or more of:");
  36.       SHOW(" +/-C - Turn Caps Lock on/off");
  37.       SHOW(" +/-N - Turn Num Lock on/off");
  38.       SHOW(" +/-S - Turn Scroll Lock on/off");
  39.       SHOW("Note switches may be upper or lower case\n");
  40.       SHOW("Example: \"KBFLIP +Cn -S\" turns Caps Lock and Num Lock on "
  41.             "and Scroll lock off");
  42.       exit(-1);
  43. }
  44.  
  45. /*
  46. **  The real works starts here
  47. **
  48. **  This works by checking the user input against a string containing the
  49. **  allowable switch characters in the same relative positions they
  50. **  occupy in the BIOS data area, offset by 4 (LOCKS_POSN).
  51. **
  52. **  Note that all changes are made to a copy of the BIOS data so any
  53. **  input errors will not cause incomplete changes to be applied.
  54. */
  55.  
  56. int main(int argc, char *argv[])
  57. {
  58.       int i, j;
  59.       char *args = "SNC";
  60.       BYTE template = *kb_status;              /* Make changes to copy */
  61.  
  62.       if (2 > argc)                             /* Help 'em             */
  63.             usage();
  64.       for (i = 1; i < argc; ++i)
  65.       {
  66.             if (NULL == strchr("+-", *argv[i]))
  67.                   usage();
  68.  
  69.             for (j = 1; argv[i][j]; ++j)
  70.             {
  71.                   char *found;
  72.  
  73.                   if (NULL != (found = strchr(args, toupper(argv[i][j]))))
  74.                   {
  75.                         int posn = LOCKS_POSN + (found - args);
  76.  
  77.                         if ('+' == *argv[i])
  78.                               template = (BYTE)BitSet(template, posn);
  79.                         else  template = (BYTE)BitClr(template, posn);
  80.                   }
  81.                   else  usage();
  82.             }
  83.       }
  84.       *kb_status = template;                    /* Apply all changes    */
  85.       return(0);
  86. }
  87.